package chapter3;

import javax.rmi.CORBA.StubDelegate;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeMap;

class Student{
    private String name;
    private int id;
    private int age;

    public Student(String name,int id,int age){
        this.name = name;
        this.id = id;
        this.age = age;
    }
    public String getName(){
        return name;
    }
    public int getAge(){
        return age;
    }
    public int getID(){
        return id;
    }
}

public class ComparatorTest {

    public static class AgeAscendingSort implements Comparator<Student>{
        public int compare(Student o1,Student o2){
            return o1.getAge() != o2.getAge() ? o1.getID()-o2.getID():o1.getAge()-o2.getAge();
        }
    }

    public static void main(String[] args) {
        Student student1 = new Student("A",2,20);
        Student student2 = new Student("B",3,23);
        Student student3 = new Student("C",1,22);
        Student[] students = new Student[]{student1,student2,student3};


        Arrays.sort(students,new AgeAscendingSort());
        for (Student s:students){
            System.out.println(s.getName());
        }
        ArrayList<Student> studentList = new ArrayList<>();

//        TreeMap<Student,String> treeMap = new TreeMap<>(new AgeAscendingSort());
        TreeMap<Student,String> treeMap = new TreeMap<>((a,b) -> a.getID() != b.getID() ?
                a.getID()-b.getID():a.hashCode()-b.hashCode());
        treeMap.put(student1,"A");
        treeMap.put(student2,"B");
        treeMap.put(student3,"C");


    }
}
